<?php

use yii\helpers\Html;
use yii\grid\GridView;

$this->title = Yii::t('app', 'Income Claims');
$this->params['breadcrumbs'][] = $this->title;
?>

<style type="text/css">
    .cs1{margin:2px 5px;} 
</style>


<div class="income-claim-index">

    <div class="box">
        <div class="box-header">
            <?= Html::a(Yii::t('app', 'Create Income Claim'), ['create','income_id'=>$income_id], ['class' => 'btn btn-success']) ?>

            <?= Html::a(Yii::t('app', 'Index'), ['/income/income/index'], ['class' => 'btn btn-danger']) ?>
        </div>

        <div class="box-body">
            <p>
                 <?php echo $this->render('_search', ['model' => $searchModel]); ?>
            </p>
            <?= GridView::widget([
                'dataProvider' => $dataProvider,
                'layout'  =>  "{items}\n{summary}\n{pager}",
                'columns' => [
                    ['class' => 'yii\grid\SerialColumn'],
                   
                    [
                        'headerOptions' => ['width' => '10%'],
                        'attribute' => 'code',
                        'value' => function ($model) {
                                return $model->code;
                            },
                    ],
                    
                    [
                        'headerOptions' => ['width' => '10%'],
                        'attribute' => 'product.code',
                        'value' => function ($model) {
                                return $model->product->code;
                            },
                    ],
                   
                    [
                        'headerOptions' => ['width' => '10%'],
                        'attribute' => 'product.name',
                        'value' => function ($model) {
                                return $model->product->name;
                            },
                    ],

                    [
                        'headerOptions' => ['width' => '10%'],
                        'attribute' => 'income.code',
                        'value' => function ($model) {
                                return $model->income->code;
                            },
                    ],

                    [
                        'attribute' => 'currency',
                        'headerOptions' => ['width' => '5%'],
                        'value' => function ($model) {
                                return isset(Yii::$app->params['currency_type'][$model->currency])?Yii::$app->params['currency_type'][$model->currency]:'';
                            },
                    ],
                    
                    [
                        'headerOptions' => ['width' => '5%'],
                        'attribute' => 'income.price',
                        'value' => function ($model) {
                                return $model->income->price;
                            },
                    ],
                    
                    [
                        'headerOptions' => ['width' => '5%'],
                        'attribute' => 'price',
                        'value' => function ($model) {
                                return $model->price;
                            },
                    ],
                  
                    [
                        'headerOptions' => ['width' => '5%'],
                        'attribute' => 'pro_price',
                        'value' => function ($model) {
                                return $model->pro_price;
                            },
                    ],
                    
                    [
                        'headerOptions' => ['width' => '5%'],
                        'attribute' => 'rate',
                        'value' => function ($model) {
                                return $model->rate;
                            },
                    ],

                    [
                        'attribute' => 'status',
                        'headerOptions' => ['width' => '5%'],
                        'value' => function ($model) {
                                return isset(Yii::$app->params['claim_status'][$model->status])?Yii::$app->params['claim_status'][$model->status]:'';
                            },
                    ],
                    
                    [
                        'headerOptions' => ['width' => '10%'],
                        'attribute' => 'remark',
                        'value' => function ($model) {
                                return $model->remark;
                            },
                    ],
                    [
                          'attribute' => 'user_id',
                          'headerOptions' => ['width' => '5%'],
                          'value' => function($model){

                                return isset($model->user) ? $model->user->name : '管理员';
                          }
                    ],
                    
                    [
                        'label'=>'操作',
                        'format'=>'raw',
                        'headerOptions' => ['width' => '15%'],
                        'value' => function($model){

                            $url  = sprintf("/income/claim/view?id=%d", $model->id); //查看
                            $url2  = sprintf("/income/claim/update?id=%d", $model->id); //更新
                            $url3  = sprintf("/income/claim/confirm?id=%d", $model->id); //收入认领

                            $str  = Html::a('查看',$url,['title' =>'查看','class'=>'btn btn-primary btn-xs cs1',]);

                            if($model->status == 1 && $model->user_id == \yii::$app->user->id){
                                $str  .= Html::a('更新',$url2,['title' =>'更新','class'=>'btn btn-success btn-xs cs1',]);
                            }

                            if($model->status == 1){
                                $str .= Html::a('确认认领', $url3, ['class' => 'btn btn-info btn-xs cs1','data' => [
                                    'confirm' => Yii::t('app', '你确定要确认吗?'),
                                    'method' => 'post',
                                ],]);
                            }
                            
                            
                            return $str;
                         }
                    ],
                ],
            ]); ?>
        </div>
    </div>

</div>
